<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    //
    protected $table = 'category';
    protected $fillable = ['weight', 'name', 'slug',];

    public function wordstarts()
    {
        return $this->hasMany(Startend::class)->where('type', 'start');
    }

    public function wordends()
    {
        return $this->hasMany(Startend::class)->where('type', 'end');
    }

    public function words()
    {
        return $this->belongsToMany(Word::class, 'word_category')->orderBy('id','asc');
    }

    /**
     * 如果你想要隐式模型绑定除 id 以外的数据库字段，你可以重写 Eloquent 模型类的 getRouteKeyName 方法：
     *
     * @return void
     */

    public function getRouteKeyName()
    {
        return 'slug';
    }
}
